<?php

class myUser extends sfGuardSecurityUser
{
  public function addDocumentToHistory($document_id)
  {
    $ids = $this->getAttribute('document_history', array());

    if (!in_array($document_id, $ids))
    {
      array_unshift($ids, $document_id);
      $this->setAttribute('document_history', array_slice($ids, 0, 3));
    }
  }

  public function getDocumentHistory()
  {
    $ids = $this->getAttribute('document_history', array());

    if (!empty($ids))
    {
      return DocumentTable::getInstance()
        ->createQuery('a')
        ->whereIn('a.id', $ids)
        ->execute();
    }
    else
    {
      return array();
    }
  }
  public function resetDocumentHistory()
  {
    $this->getAttributeHolder()->remove('document_history');
  }
  public function getId()
  {
    return $this->getGuardUser()->getId();
  }
}
